package com.cat.dynamicPlanning02;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/task-scheduler-ii/
 * @create 2025/11/6 15:45
 * @since JDK17
 */

public class Solution49 {
    public long taskSchedulerII(int[] tasks, int space) {
        Map<Integer, Long> last = new HashMap<>();
        long day = 0;
        for (int x : tasks) {
            if (last.containsKey(x)) {
                day = Math.max(day + 1, last.get(x) + space + 1);
            } else {
                day++;
            }
            last.put(x, day);
        }

        return day;
    }
}
